package com.ruoyi.app.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.ruoyi.app.domain.vo.ShopInfoVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.app.domain.ShopInfo;
import com.ruoyi.app.service.IShopInfoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 店铺信息Controller
 * 
 * @author ruoyi
 * @date 2023-12-21
 */
@ApiOperation(value = "店铺信息", tags = "企业管理")
@RestController
@RequestMapping("/shop/info")
public class ShopInfoController extends BaseController
{
    @Autowired
    private IShopInfoService shopInfoService;

    /**
     * 查询店铺信息列表
     */
    @PreAuthorize("@ss.hasPermi('shop:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShopInfo shopInfo)
    {
        startPage();
        List<ShopInfo> list = shopInfoService.selectShopInfoList(shopInfo);
        return getDataTable(list);
    }

    /**
     * 导出店铺信息列表
     */
    @PreAuthorize("@ss.hasPermi('shop:info:export')")
    @Log(title = "店铺信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopInfo shopInfo)
    {
        List<ShopInfo> list = shopInfoService.selectShopInfoList(shopInfo);
        ExcelUtil<ShopInfo> util = new ExcelUtil<ShopInfo>(ShopInfo.class);
        util.exportExcel(response, list, "店铺信息数据");
    }

    /**
     * 获取店铺信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(shopInfoService.selectShopInfoById(id));
    }

    /**
     * 新增店铺信息
     */
    @PreAuthorize("@ss.hasPermi('shop:info:add')")
//    @ApiOperation("添加企业信息")
    @Log(title = "店铺信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ShopInfo shopInfo)
    {
        return toAjax(shopInfoService.save(shopInfo));
    }

    /**
     * 修改店铺信息
     */
    @PreAuthorize("@ss.hasPermi('shop:info:edit')")
    @Log(title = "店铺信息", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody ShopInfo shopInfo)
    {
        return toAjax(shopInfoService.updateById(shopInfo));
    }

    /**
     * 删除店铺信息
     */
    @PreAuthorize("@ss.hasPermi('shop:info:remove')")
    @Log(title = "店铺信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        List<String> objects = Arrays.asList(ids);
        return toAjax(shopInfoService.removeByIds(objects));
    }


    /**
     * 新增店铺信息
     */
    @ApiOperation("用户创建店铺")
    @Log(title = "店铺信息", businessType = BusinessType.INSERT)
    @PostMapping("/createShopInfo")
    public AjaxResult createShopInfo(@RequestBody ShopInfoVo shopInfoVo)
    {
        String id = getLoginUser().getUser().getId();
        shopInfoVo.setUserId(id);
        return toAjax(shopInfoService.createShopInfo(shopInfoVo));
    }



    /**
     * 新增店铺信息
     */
    @ApiOperation("本月统计")
    @GetMapping("/currentMonthStatistics")
    public AjaxResult currentMonthStatistics()
    {
        ShopInfoVo shopInfoVo = new ShopInfoVo();
        String id = getLoginUser().getUser().getId();
        shopInfoVo.setUserId(id);
        shopInfoVo.setId(getShopId());
        ShopInfoVo shopInfo = shopInfoService.currentMonthStatistics(shopInfoVo);
        return success().setData(shopInfo);
    }

}
